package com.core.service;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import com.core.dao.DAOException;
import com.core.dao.DAOFactory;
import com.core.dao.impl.CatagoryDAOImpl;
import com.core.entities.Catagory;

public class CatagorySrv {
	private Connection conn;
	private CatagoryDAOImpl catagoryDAOImpl;
	
	public CatagorySrv(Connection conn){
		this.conn = conn;
	}
	public List<String> getCatagoryNames(){
		List<String> catagoryNames = new ArrayList<String>();
		try{
			for(Catagory catagory : DAOFactory.getInstance().getCatagoryDAO(conn).selectAll())
				catagoryNames.add(catagory.getName());
		}catch(DAOException e){
			e.printStackTrace();
		}
		return catagoryNames;
	}
	
	public int getCatagoryPK(String catagoryName){
		try{
			return DAOFactory.getInstance().getCatagoryDAO(conn).getByName(catagoryName).get(0).getId();
		}catch(DAOException e){
			e.printStackTrace();
		}
		return -1;
	}
	
	public CatagoryDAOImpl getCatagoryDAO() throws DAOException{
		if(catagoryDAOImpl == null)
			catagoryDAOImpl =(CatagoryDAOImpl) DAOFactory.getInstance().getCatagoryDAO(conn);
		return catagoryDAOImpl;
	}

}
